import os
import platform


# 编写一个类实现文件相对路径读取功能
class Properties:
    def __init__(self, filename, isroot):
        self.filename = filename
        self.isroot = isroot

    def getfilepath(self):
        if self.isroot:
            if platform.system() == "Windows":
                return os.path.abspath("..") + "\\" + self.filename
            else:
                return os.path.abspath("..") + "/" + self.filename
        else:
            if platform.system() == "Windows":
                return os.path.abspath(".") + "\\" + self.filename
            else:
                return os.path.abspath(".") + "/" + self.filename

    def getProperties(self):
        properties = {}
        filepath = self.getfilepath()
        lines = open(filepath, "r").readlines()
        for line in lines:
            if line.find('=') > 0:
                strs = line.replace('\n', '').split('=')
                properties[strs[0]] = strs[1]
        return properties
